#include "stdio.h"
#include "stdbool.h"
#include "time.h"
#include <string.h>

enum MONTH
{
	Jan = 31,
	Feb = 28,
	Mar = 31,
	Apr = 30,
	May = 31,
	Jun = 30,
	Jul = 31,
	Aug = 31,
	Sep = 30,
	Oct = 31,
	Nov = 30,
	Dec = 31,
};

//Thu 23 Sep 2021 09:14:23 CST
int main(void)
{

    char	data[256];
    int	time_stamp;
    printf("请输入时间：如(Thu 23 Sep 2021 09:14:23 CST)\n");

    gets(data);
    
    puts(data);
  
    time_stamp = get_time_stamp(data);
    
    printf("时间戳为:%d\n", time_stamp);
    

}

int get_time_stamp(char *data)
{
	int	i=0,j=0;
	char	DATE[10][10];
	while( (*data != ' ' && *data != '\0') ||  *data != '\0' )//判断是否为空
	{
		
			DATE[i][j++] = *data;
			data++;
			
			if( *data == ' ' || *data == ':' )
			{
				DATE[i][j] = '\0';
				i++;
				data++;
				j = 0;
			}
		
	}
	int sec = atoi(DATE[6]);
	int cnt = runnian( atoi(DATE[3]) );
	int time_stamp = sec + min_sec(DATE[5]) + hour_sec(DATE[4]) + mday_sec(DATE[1]) + mon_sec(DATE[2],cnt) + year_sec(DATE[3]);
	printf("闰年次数：%d\n", cnt);
	return time_stamp;
}

int min_sec(char *min)
{
	int  Min;
	Min = atoi(min);
	int sum_min = Min*60;
	return sum_min;
}

int hour_sec(char *hour)
{
	int  Hour;
	Hour = atoi(hour);
	int sum_hour = (Hour-8)*60*60;
	return sum_hour;
}


int mday_sec(char *mday)
{
	int  Mday;
	Mday = atoi(mday);
	int sum_mday = (Mday-1)*24*60*60;
	return sum_mday;
}

int runnian(char *Year)
{
	int year,cnt=0;
	
	for(year = 1970; year <= Year; year++)
	
	if((year%4 == 0 && year%100 != 0) || year%400 == 0) 
	{		
		cnt++;
	}
	
	return cnt;
}

int mon_sec(char *Mon, int cnt)
{
		
	int sum_mon = 0;
	
	if( strcmp(Mon, "Jan") == 0 )
	{
		sum_mon = (cnt-1)*24*60*60;
	}
	if( strcmp(Mon, "Feb") == 0 )
	{
		sum_mon = (Jan+cnt-1)*24*60*60;
	}
	if( strcmp(Mon, "Mar") == 0 )
	{
		sum_mon = (Jan+Feb+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Apr") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+cnt)*24*60*60;
	}
	if( strcmp(Mon, "May") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+Apr+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Jun") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+Apr+May+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Jul") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+Apr+May+Jun+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Aug") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+Apr+May+Jun+Jul+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Sep") == 0)
	{
		sum_mon = (Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Oct") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Nov") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct+cnt)*24*60*60;
	}
	if( strcmp(Mon, "Dec") == 0 )
	{
		sum_mon = (Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct+Nov+cnt)*24*60*60;
	}
	
	
	return sum_mon;
}

int year_sec(char *year)
{
   int y_sum,Year;
   
   Year = atoi(year);
   
   int sum_year = (Year-1970)*365*24*60*60;
   
   return sum_year;
}


